package fun.hijklmn.magic.idGenerator.server.controller;


import fun.hijklmn.magic.idGenerator.common.enums.ServerTypeEnum;
import fun.hijklmn.magic.idGenerator.server.service.WorkerNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * DB WorkerID Assigner for UID Generator 前端控制器
 * </p>
 *
 * @author zsl
 * @since 2021-07-12
 */
@Slf4j
@Api(value = "ID生成服务", tags = "ID生成服务")
@RestController
@RequestMapping("/id")
public class WorkerNodeController {

    @Autowired
    private WorkerNodeService workerNodeService;

    @ApiOperation(value = "获取ID", tags = "ID生成服务")
    @GetMapping("get")
    public String get(ServerTypeEnum serverTypeEnum) {
        String id = workerNodeService.get(serverTypeEnum);
        log.info("--------->serverName:{}; idType:{}; content:{};", serverTypeEnum.serverName(), serverTypeEnum.shortCode(), id);
        return id;
    }

}

